package com.ch.dsms_backend.controller;

import com.ch.dsms_backend.entity.GoodsType;
import com.ch.dsms_backend.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;

    @CrossOrigin //跨域访问
    @RequestMapping("/showAllTypes")
    public List<GoodsType> showAllTypes(HttpSession session){
        return typeService.showAllTypes();
    }

    @CrossOrigin //跨域访问
    @RequestMapping("/selectAllTypeByPage")
    public String selectAllTypeByPage(Model model,int currentPage){
        return typeService.selectAllTypeByPage(model,currentPage);
    }

    @CrossOrigin //跨域访问
    @RequestMapping("/deleteType")
    @ResponseBody   //返回字符串数据而非视图
    public String delete(int id){
        return typeService.delete(id);
    }

    @CrossOrigin //跨域访问
    @RequestMapping("/toAddType")
    public String toAddType(@ModelAttribute("goodsType") GoodsType goodsType){
        return "admin/addType";
    }

    @CrossOrigin //跨域访问
    @RequestMapping("/addType")
    public String addType(String typename){
        return typeService.addType(typename);
    }

}
